package user_profile

import (
	"context"

	"algo-sdk-go/project/matchmaking/application/command"
	"algo-sdk-go/project/matchmaking/common/constant"
	"algo-sdk-go/project/matchmaking/matchMaking-api/internal/svc"
	"algo-sdk-go/project/matchmaking/matchMaking-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AppendUserprofileLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAppendUserprofileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppendUserprofileLogic {
	return &AppendUserprofileLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AppendUserprofileLogic) AppendUserprofile(req *types.AppendUserprofileRequest) (resp *types.SyncUserprofileResponse, err error) {
	userNum, err := l.svcCtx.UserProfileService.AppendUserProfile(l.ctx, TransAppendUserprofileCommand(req))
	if err != nil {
		return nil, err
	}

	resp = &types.SyncUserprofileResponse{
		Data: types.SyncUserprofileData{
			UserNum: userNum,
		},
	}
	return
}

func TransAppendUserprofileCommand(req *types.AppendUserprofileRequest) command.AppendUserprofileCommand {
	return command.AppendUserprofileCommand{
		UserNum:       req.UserNum,
		UserAvatar:    req.UserAvatar,
		Gender:        constant.Gender(req.Gender),
		BirthDate:     req.BirthDate,
		Height:        req.Height,
		Weight:        req.Weight,
		MaritalStatus: constant.MaritalStatus(req.MaritalStatus),
		Education:     constant.Education(req.Education),
		Assets: constant.AssetInfo{
			AnnualIncome: req.Assets.AnnualIncome,
			Car:          constant.AssetStatus(req.Assets.Car),
			House:        constant.AssetStatus(req.Assets.House),
		},
		Occupation:       constant.Occupation(req.Occupation),
		Hometown:         req.Hometown,
		CurrentResidence: req.CurrentResidence,
	}
}
